<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ include file="../../../views/include/taglib.jsp"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>服务项目管理</title>
<head>
    <meta charset="utf-8">
    <title>服务项目管理</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">

    <link rel="stylesheet" href="/fdoctor-ms/statics/beginnerAdmin/plugins/layui/css/layui.css" media="all" />
    <link rel="stylesheet" href="/fdoctor-ms/statics/beginnerAdmin/plugins/font-awesome/css/font-awesome.min.css">
    <link rel="stylesheet" href="/fdoctor-ms/statics/beginnerAdmin/css/btable.css" />
    
    <script type="text/javascript" src="/fdoctor-ms/statics/beginnerAdmin/plugins/layui/layui.js"></script>
    <script type="text/javascript" src="/fdoctor-ms/statics/js/jquery-2.1.4.min.js"></script>
    
</head>

<body style=" background-color: gainsboro;">

    <div style="margin:0px; background-color: white;">
        <blockquote class="layui-elem-quote">
        <form class="layui-form" action="">
        <div class="layui-inline" >
        <label class="layui-form-label" style="width: 150px;font-size: 26px; ">服务包</label>
        </div>   
        <div class="layui-inline" style="width: 35%;" >
			<div class="layui-input-inline" ">
			<select name="Level" id="Level"  lay-verify="" lay-filter="Level">
					<option value="">--请选择服务包--</option>
				      	<c:forEach items="${packList}" var="item"  varStatus="varStatus">
				      		<option value="${item.id}" <c:if test="${varStatus.isFirst()}">selected</c:if>>${item.packName}</option>
				       </c:forEach>
				</select>     
			</div>
		</div>
		<div class="layui-inline" >
			    	 <div class="layui-input-inline">
			    	<button class="layui-btn layui-btn-radius" style="width: 60%;margin-left:250px;" id="selectButton" type="button">查询</button>
			    	</div>
			    </div>
			    <!--
         <div class="layui-form-item" align="left" style="margin-left: 0px;margin-top: 10px;">
          
            	<label class="layui-form-label" style="width: 120px;font-size: 26px; ">行政区划</label>
			  	<div class="layui-inline" style="width: 16%;">
			    <div class="layui-input-inline" ">
			      <select name="oneLevel" id="oneLevel"  lay-verify="" lay-filter="oneLevel">
					  <option value="0">--请选择市(州)--</option>
					  	<c:forEach items="${oneList}" var="item">
				      		<option value="${item.regionCode}">${item.name}</option>
				       	</c:forEach>
				    </select>     
			    </div>
			    </div>
			  	<div class="layui-inline" style="width: 16%;">
			    <div class="layui-input-inline">
			      <select name="twoLevel" id="twoLevel"  lay-verify="" lay-filter="twoLevel">
					  <option value="0">--请选择县(区)--</option>
					</select>     
			    </div>
			    </div>
			    <div class="layui-inline" style="width: 16%;">
			    <div class="layui-input-inline">
			      <select name="threeLevel" id="threeLevel"  lay-verify="" lay-filter="threeLevel">
					  <option value="0">--请选择镇(乡)--</option>
					</select>    
			    </div>
			    </div>
			    
			    <div class="layui-inline" style="width: 20%;">
			    	 <div class="layui-input-inline">
			    	<button class="layui-btn layui-btn-radius" style="width: 60%;margin-left:250px;" id="selectButton" type="button">查询</button>
			    	</div>
			    </div>
			    
			  </div>
			   -->
			</form>
        </blockquote>
		<div class="layui-btn-group">
		<c:if test="${fn:length(sessionScope.user_in_session.orgIds)> 1}">  
		  <button class="layui-btn layui-btn-primary layui-btn-small" id="addButton"><i class="layui-icon">&#xe654;</i>新增服务项目</button>
		  <button class="layui-btn layui-btn-primary layui-btn-small" id="deleteButton"><i class="layui-icon">&#xe640;</i>删除服务项目</button>
		</c:if> 
		</div>
        <div id="content" style="width: 100%;height: 500px;"></div>
    </div>

    <script>
    
	    
    
    	function tableConfig(){
    		layui.config({
                base: '/fdoctor-ms/statics/beginnerAdmin/js/'
            }).use(['btable','layer'], function () {
                var layer = layui.layer;
                
                var btable = layui.btable(),
                    $ = layui.jquery;
                
                //layer.config({
                	//id : Math.ceil(100)	//防止重复弹窗
                //});
				btable.set({
                elem: '#content',
                url: '/fdoctor-ms/servicePack/getPackDetails',
                type: 'GET',
                pageSize: 100,
                columns: [{
                    fieldName: '服务包id',
                    field: 'id',
                    //hidden:	true
                },{
                    fieldName: '服务项目',
                    field: 'serviceName'
                }, {
                    fieldName: '描述',
                    field: 'serviceDetails'
                }, {
                    fieldName: '频率',
                    field: 'frequency',
                    colRender : 'typeRender'
                }],
                even: true,
                //skin: 'row',
                checkbox: true,
                field: 'id',
                paged: true,
                singleSelect: true,
                params :packParams(),
            });
            btable.render();
                
                $('#addButton').on('click', function () {
                    //获取选择的数据
                   if($('#Level').val() == "0"){
                    		layer.msg('请选择上方的服务包名称',{icon: 7,id : Math.ceil(100)});
                    	}else{
                    		layer.open({
                         		  type: 2,
                         		  title: false,
                         		  id : Math.ceil(100),
                         		  area: ['550px', '400px'],
                         		  closeBtn: 1,
                         		  content: '/fdoctor-ms/servicePack/addRelation?id='+$('#Level').val()
                          	});
                    	}
                    
                });
                
                $('#deleteButton').on('click',function (){
                  	 //获取选择的数据
                      btable.getSelections(function (obj) {
                      	if(obj.count == 0){
                      		layer.msg('请选择要删除的数据',{icon: 7,id : Math.ceil(100)});
                      	}else{
                      		layer.confirm('确认删除？', {icon: 3,id : Math.ceil(100)}, function(index){
                      			$.ajax({
              						type : 'POST',
              						url : '/fdoctor-ms/servicePack/deleteRelation',
              						data : {
              							detailId : obj.ids[0],
              							sigId : $('#Level').val()
              						},
              						success : function(data) {
              							if (data.code == 200) {
              								layer.msg('删除成功！', {
              									icon : 1
              								});
              								tableConfig();
              							} else {
              								layer.msg('删除失败！', {
              									icon : 2
              								});
              							}
              						}
              					});
                     			});
                      	}
                      });
                  });
                
                $(window).on('resize', function (e) {
                    var $that = $(this);
                    $('#content').height($that.height() - 92);
                }).resize();
                
            });
    	}
    	
    	tableConfig();
    
    	//查询按钮声明点击事件，查询逻辑
        $('#selectButton').on('click', function(){
        	tableConfig();
        });
  	  	//初始化表单控件
  	  	layui.use(['jquery', 'form'], function() {
		     $ = layui.jquery;
		     form = layui.form();
		     $form = $('form');
		   
		});
           
        function packParams(){
			var params={
					id:$('#Level').val(),
					//regionCode:Code
			}
			return params;
        
        }
		function typeRender(data){
        	if(data == '-1'){
        		return '总是';
        	}else{
        		return data+"次/年";
        	}
        }
    </script>
</body>
</html>